package com.gasstation

import com.gasstation.domain.GasUtil

class InventoryRegularController {

	static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

	def index = {
		redirect(action: "list", params: params)
	}

	def list = {
		params.max = Math.min(params.max ? params.int('max') : 10, 100)
		[inventoryRegularInstanceList: InventoryRegular.list(params), inventoryRegularInstanceTotal: InventoryRegular.count()]
	}
	def listAsPerMonth = {
		params.max = Math.min(params.max ? params.int('max') : 10, 100)
		def c = InventoryRegular.createCriteria()
		Date month = params.monthYear
		if(month == null){
			month = new Date()
		}
		def regularInvList = c.list{between("transactionOn", GasUtil.getFirstDayOfMonth(month), GasUtil.getLastDayOfMonth(month))}
		render(view: "list", model: [inventoryRegularInstanceList:regularInvList, monthYear:month, inventoryRegularInstanceTotal: InventoryRegular.count()])
	}
}
